package com.chenyun.system.generator.controller;

import com.chenyun.system.generator.model.GenDatasourceStore;
import com.chenyun.system.generator.service.IGenDatasourceStoreService;
import com.chenyun.boot.web.controller.BaseController;
import com.chenyun.common.vo.AjaxResult;
import com.chenyun.common.vo.PageResult;
import com.chenyun.satoken.starter.annotation.SaCheckAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 数据源管理Controller
 * 
 * @author ruoyi
 * @date 2022-06-27
 */
@RestController
@RequestMapping("/tool/gen/datasource")
@SaCheckAdmin
public class GenDatasourceStoreController extends BaseController<IGenDatasourceStoreService, GenDatasourceStore>
{
    @Autowired
    private IGenDatasourceStoreService genDatasourceStoreService;

    /**
     * 查询数据源管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:store:list')")
    @GetMapping("/list")
    public PageResult list(GenDatasourceStore genDatasourceStore)
    {
        //startPage();
        List<GenDatasourceStore> list = genDatasourceStoreService.selectGenDatasourceStoreList(genDatasourceStore);
        return getDataTable(list);
    }



    /**
     * 获取数据源管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:store:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.SUCCESS(genDatasourceStoreService.selectGenDatasourceStoreById(id));
    }

    /**
     * 新增数据源管理
     */
    //@PreAuthorize("@ss.hasPermi('system:store:add')")
    //@Log(title = "数据源管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add( GenDatasourceStore genDatasourceStore)
    {
        genDatasourceStore.setUrl(genDatasourceStore.getJdbcUrl());
        return toAjax(genDatasourceStoreService.insertGenDatasourceStore(genDatasourceStore));
    }

    /**
     * 修改数据源管理
     */
    //@PreAuthorize("@ss.hasPermi('system:store:edit')")
    //@Log(title = "数据源管理", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody GenDatasourceStore genDatasourceStore)
    {  genDatasourceStore.setUrl(genDatasourceStore.getJdbcUrl());
        return toAjax(genDatasourceStoreService.updateGenDatasourceStore(genDatasourceStore));
    }

    /**
     * 删除数据源管理
     */
    //@PreAuthorize("@ss.hasPermi('system:store:remove')")
    //@Log(title = "数据源管理", businessType = BusinessType.DELETE)
	@PostMapping("del")
    public AjaxResult remove(@RequestBody String[] ids)
    {
        return toAjax(genDatasourceStoreService.deleteGenDatasourceStoreByIds(ids));
    }
}
